package com.demo.coupon;


import com.demo.util.Utils;
import com.demo.AppletConstant;

import java.util.HashMap;
import java.util.Map;


/**
 * 抽奖
 *
 */
public class QualReduce {
	public static void main(String[] args)  throws Exception{

		//调用接口地址
		String url = "https://open.95516.com/open/access/1.0/qual.reduce";
		
		//拼装参数Map
		Map<String, String> params = new HashMap<String, String>(0);
		params.put("appId", AppletConstant.APP_ID);
		params.put("activityNumber", "");
		params.put("orderAmount", "");
		params.put("qualNum", "");
		params.put("qualType", "");
		params.put("qualValue", "");
		params.put("certId", "");
		params.put("icTerminal", "");
		params.put("qrCode", "");
		//流水号（确保唯一）
		String transNumber = Utils.createNonceNumber();
		params.put("transNumber", transNumber);

		//生成时间戳
		String timestamp = String.valueOf(System.currentTimeMillis()/1000);
		params.put("timestamp", timestamp);

		//生成随即字符串
		String nonceStr = Utils.createNonceStr();
		params.put("nonceStr", nonceStr);
		//签名
		String signature = Utils.sign(params, AppletConstant.SIGN_KEY_PACKET);
		params.put("signature", signature);

		//针对敏感字段加密
		Utils.encryptedParamMap(AppletConstant.SYMMETRIC_KEY, params, "qualValue", "certId");
		//发送请求
		String resultStr = Utils.sendPostGson(url, params);
		
		System.out.println("-------抽奖（红包/票券）返回:"+resultStr+"---------");
	}
	
}
